package 力扣算法练习.main1.newPart1;

import java.util.Stack;

public class day5 {
    //https://www.nowcoder.com/questionTerminal/d8acfa0619814b2d98f12c071aef20d4
    public boolean chkParenthesis(String A, int n) {
        // write code here
        char[] ch = A.toCharArray();
        Stack<Character> temp = new Stack<>();
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] == '(') {
                temp.add(ch[i]);
            } else if (ch[i] == ')') {
                if (temp.isEmpty()) {
                    return false;
                } else {
                    temp.pop();
                }
            } else {
                return false;
            }
        }
        if (!temp.isEmpty()) {
            return false;
        }
        return true;
    }

    //https://www.nowcoder.com/practice/839f681bf36c486fbcc5fcb977ffe432?tpId=122&tqId=33666&ru=/exam/oj
    public static void find(String[]instr) {
            //将内容读出
            //判断是不是根据长度排序
            boolean flag1=findLength(instr);
            //判断是不是根据字典顺序排序
            boolean flag2=true;
            for(int i=0;i<instr.length-1;i++){
                if(!findLetter(instr[i],instr[i+1])){
                    flag2=false;
                    break;
                }
            }

            if(flag1&&flag2){
                System.out.println("both");
            }else if(flag1){
                System.out.println("lengths");
            }else if(flag2){
                System.out.println("lexicographically");
            }else{
                System.out.println("none");
            }

    }
    private static boolean findLength(String[] instr){
        for(int i=0;i<instr.length-1;i++){
            if(instr[i].length()>instr[i+1].length()){
                return false;
            }
        }
        return true;
    }
    private static boolean findLetter(String str1,String str2){
        int len1=str1.length();
        int len2=str2.length();
        int i1=0,i2=0;
        while(i1<len1&&i2<len2){
            if(str1.charAt(i1)>str2.charAt(i2)){
                return false;
            }else if (str1.charAt(i1)<str2.charAt(i2)){
                return true;
            }
            i1++;
            i2++;
        }
        return true;
    }

    public static void main(String[] args) {
        String[] str =new String[2];
//        str[0]="afzmd";
//        str[1]="aizgprtuchtxouwtqgzxnvmcaoitzpxqrcaltloukiygnmc";
//        str[2]="akqkikdgnhduisqawpznqxpdlnfwslquxoptulfxlwuufinsdf";
//        str[3]="bjltywdrgpjteyg";
//        str[4]="cwewapumhggpsescaudk";
//        str[5]="fzkexkpdvllsozehdqqkerhvlrc";
//        str[6]="hsresaf";
//        str[7]="nrgvhmfueoaqvxodwzibkcdpdnafhepeujbxoomxmrltozlkc";
//        str[8]="sgoqtrfaehdncijxvoilpxvnkjoiiaxpclzlkmowrx";
//        str[9]="wkwdjzagzyklffbhdqkbadssly";
        str[0]="aaa";
        str[1]="z";
        find(str);
    }
}
